package com.ruoyi.web.service.Impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.vo.CareDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.mapper.MesMachineCaredetailMapper;
import com.ruoyi.web.domain.mes.MesMachineCaredetail;
import com.ruoyi.web.service.IMesMachineCaredetailService;

import javax.annotation.Resource;

/**
 * 设备保养记录Service业务层处理
 * 
 * @author levicash
 * @date 2024-01-15
 */
@Service
public class MesMachineCaredetailServiceImpl implements IMesMachineCaredetailService 
{
    @Resource
    private MesMachineCaredetailMapper mesMachineCaredetailMapper;

    /**
     * 查询设备保养记录
     * 
     * @param id 设备保养记录主键
     * @return 设备保养记录
     */
    @Override
    public MesMachineCaredetail selectMesMachineCaredetailById(Long id)
    {
        return mesMachineCaredetailMapper.selectMesMachineCaredetailById(id);
    }

    /**
     * 查询设备保养记录列表
     * 
     * @param mesMachineCaredetail 设备保养记录
     * @return 设备保养记录
     */
    @Override
    public List<MesMachineCaredetail> selectMesMachineCaredetailList(MesMachineCaredetail mesMachineCaredetail)
    {
        return mesMachineCaredetailMapper.selectMesMachineCaredetailList(mesMachineCaredetail);
    }

    /**
     * 新增设备保养记录
     * 
     * @param mesMachineCaredetail 设备保养记录
     * @return 结果
     */
    @Override
    public int insertMesMachineCaredetail(MesMachineCaredetail mesMachineCaredetail)
    {
//        mesMachineCaredetail.setCreateBy(SecurityUtils.getUsername());
//        mesMachineCaredetail.setCreateTime(DateUtils.getNowDate());
        mesMachineCaredetail.setUpdateTime(DateUtils.getNowDate());
        Random random = new Random();
        mesMachineCaredetail.setCode(StringUtils.createCode(random));
        mesMachineCaredetail.setOperator(SecurityUtils.getUsername());
        mesMachineCaredetail.setOperatorId(SecurityUtils.getUserId().toString());
        return mesMachineCaredetailMapper.insertMesMachineCaredetail(mesMachineCaredetail);
    }

    /**
     * 修改设备保养记录
     * 
     * @param mesMachineCaredetail 设备保养记录
     * @return 结果
     */
    @Override
    public int updateMesMachineCaredetail(MesMachineCaredetail mesMachineCaredetail)
    {
        mesMachineCaredetail.setUpdateBy(SecurityUtils.getUsername());
        mesMachineCaredetail.setUpdateTime(DateUtils.getNowDate());
        return mesMachineCaredetailMapper.updateMesMachineCaredetail(mesMachineCaredetail);
    }

    /**
     * 批量删除设备保养记录
     * 
     * @param ids 需要删除的设备保养记录主键
     * @return 结果
     */
    @Override
    public int deleteMesMachineCaredetailByIds(Long[] ids)
    {
        return mesMachineCaredetailMapper.deleteMesMachineCaredetailByIds(ids);
    }

    /**
     * 删除设备保养记录信息
     * 
     * @param id 设备保养记录主键
     * @return 结果
     */
    @Override
    public int deleteMesMachineCaredetailById(Long id)
    {
        return mesMachineCaredetailMapper.deleteMesMachineCaredetailById(id);
    }

    /**
     * 查询设备保养记录关联列表
     *
     * @param map 查询参数
     * @return 设备保养记录关联集合
     */
    @Override
    public List<CareDetailVo> selectMesMachineCaredetailAll(Map<String, Object> map)
    {
        return mesMachineCaredetailMapper.selectMesMachineCaredetailAll(map);
    }

    /**
     * 批量修改设备保养记录状态
     *
     * @param status 设备保养记录状态
     * @param detailIds 设备保养记录ids
     * @return 结果
     */
    @Override
    public int updateMesMachineCaredetailByIds(int status, Long[] detailIds)
    {
        return mesMachineCaredetailMapper.updateMesMachineCaredetailByIds(status,detailIds);
    }

}
